
import java.io.File;
import java.io.Serializable;

class Track implements Serializable{

  //Track's location in this host
  private String location;

  //Track's title
  private String title;

  //Track's creator
  private String creator;

  //Track's hoster
  private String serverName;

  //Track's hoster
  private String nodeName;

  //TODO implementar el equals para que compare el host también y no la referencia!!

  /**
   * This object stores necesary information for finding a track between nodes
   */
  Track(String location, String title, String creator, String nodeName)
    throws TrackException
  {

    if (null == location){
      throw new TrackException("No se especificó la ubicación del archivo");
    }
    if (null == title){
      throw new TrackException("No se especificó el nombre de la canción");
    }
    if (null == creator){
      throw new TrackException("No se especificó el creador de la canción");
    }
    if (null == nodeName){
      throw new TrackException("No se especificó el nombre de nodo de la canción");
    }

    File f = new File(location);
    if (!f.exists()){
      throw new TrackException("La canción ubicada en '" + location + "' no existe");
    }

    this.location = location;
    this.title = title;
    this.creator = creator;
    this.nodeName = nodeName;
  }

  public String getLocation(){
    return location;
  }

  public String getCreator(){
    return creator;
  }

  public String getTitle(){
    return title;
  }

  public String getNodeName(){
    return nodeName;
  }

  public void setServerName(String serverName){
    this.serverName = serverName;
  }

  public String getServerName(){
    return serverName;
  }

  /**
   * String representation of this track. It is for debugging purposes
   */
  public String toString(){
    return "title: " + title +
           " creator: " + creator +
           " location: " + location +
           " serverName: " + serverName;
  }
}